home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / ioport / iotest5.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-10  |  14.2 KB  |  413 lines

  1. VERSION 5.00
  2. Object = "{9FF7F1C2-9FA2-11D1-8FF6-30B803C10627}#1.0#0"; "IOPORT.OCX"
  3. Begin VB.Form ioporttest 
  4.    Caption         =   "I/O Port Test "
  5.    ClientHeight    =   4305
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   5715
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4305
  11.    ScaleWidth      =   5715
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.TextBox txtusread 
  14.       BeginProperty Font 
  15.          Name            =   "Arial Black"
  16.          Size            =   12
  17.          Charset         =   0
  18.          Weight          =   400
  19.          Underline       =   0   'False
  20.          Italic          =   0   'False
  21.          Strikethrough   =   0   'False
  22.       EndProperty
  23.       Height          =   360
  24.       Left            =   3720
  25.       TabIndex        =   15
  26.       Top             =   2040
  27.       Width           =   1572
  28.    End
  29.    Begin VB.TextBox txtuswrite 
  30.       BeginProperty Font 
  31.          Name            =   "Arial Black"
  32.          Size            =   12
  33.          Charset         =   0
  34.          Weight          =   400
  35.          Underline       =   0   'False
  36.          Italic          =   0   'False
  37.          Strikethrough   =   0   'False
  38.       EndProperty
  39.       Height          =   372
  40.       Left            =   3720
  41.       TabIndex        =   14
  42.       Top             =   1320
  43.       Width           =   1572
  44.    End
  45.    Begin IOPORTLib.Ioport Ioport1 
  46.       Left            =   4080
  47.       Top             =   2760
  48.       _Version        =   65536
  49.       _ExtentX        =   1503
  50.       _ExtentY        =   1503
  51.       _StockProps     =   0
  52.    End
  53.    Begin VB.CommandButton cmdexit 
  54.       Caption         =   "E&xit"
  55.       Height          =   375
  56.       Left            =   2400
  57.       TabIndex        =   12
  58.       Top             =   3480
  59.       Width           =   735
  60.    End
  61.    Begin VB.TextBox txtaddress 
  62.       BeginProperty Font 
  63.          Name            =   "Arial Black"
  64.          Size            =   12
  65.          Charset         =   0
  66.          Weight          =   400
  67.          Underline       =   0   'False
  68.          Italic          =   0   'False
  69.          Strikethrough   =   0   'False
  70.       EndProperty
  71.       Height          =   375
  72.       Left            =   360
  73.       TabIndex        =   6
  74.       Text            =   "0"
  75.       Top             =   3480
  76.       Width           =   1575
  77.    End
  78.    Begin VB.TextBox txtbitsize 
  79.       BeginProperty Font 
  80.          Name            =   "Arial Black"
  81.          Size            =   12
  82.          Charset         =   0
  83.          Weight          =   400
  84.          Underline       =   0   'False
  85.          Italic          =   0   'False
  86.          Strikethrough   =   0   'False
  87.       EndProperty
  88.       Height          =   375
  89.       Left            =   360
  90.       TabIndex        =   5
  91.       Text            =   "0"
  92.       Top             =   2760
  93.       Width           =   1575
  94.    End
  95.    Begin VB.TextBox txtwrite 
  96.       BeginProperty Font 
  97.          Name            =   "Arial Black"
  98.          Size            =   12
  99.          Charset         =   0
  100.          Weight          =   400
  101.          Underline       =   0   'False
  102.          Italic          =   0   'False
  103.          Strikethrough   =   0   'False
  104.       EndProperty
  105.       Height          =   375
  106.       Left            =   360
  107.       TabIndex        =   4
  108.       Text            =   "0"
  109.       Top             =   1320
  110.       Width           =   1575
  111.    End
  112.    Begin VB.CommandButton cmdwrite 
  113.       Caption         =   "&Write to port"
  114.       Height          =   375
  115.       Left            =   2160
  116.       TabIndex        =   3
  117.       Top             =   1320
  118.       Width           =   1335
  119.    End
  120.    Begin VB.CommandButton cmdbitsize 
  121.       Caption         =   "&Toggle Bit size"
  122.       Height          =   375
  123.       Left            =   2160
  124.       TabIndex        =   2
  125.       Top             =   2760
  126.       Width           =   1335
  127.    End
  128.    Begin VB.TextBox txtvalue 
  129.       BeginProperty Font 
  130.          Name            =   "Arial Black"
  131.          Size            =   12
  132.          Charset         =   0
  133.          Weight          =   400
  134.          Underline       =   0   'False
  135.          Italic          =   0   'False
  136.          Strikethrough   =   0   'False
  137.       EndProperty
  138.       Height          =   375
  139.       Left            =   360
  140.       TabIndex        =   1
  141.       Text            =   "0"
  142.       Top             =   2040
  143.       Width           =   1575
  144.    End
  145.    Begin VB.CommandButton cmdread 
  146.       Caption         =   "&Read from port"
  147.       Height          =   375
  148.       Left            =   2160
  149.       TabIndex        =   0
  150.       Top             =   2040
  151.       Width           =   1335
  152.    End
  153.    Begin VB.Label lblusread 
  154.       Height          =   252
  155.       Left            =   3720
  156.       TabIndex        =   17
  157.       Top             =   1800
  158.       Width           =   1812
  159.    End
  160.    Begin VB.Label lbluswrite 
  161.       Height          =   252
  162.       Left            =   3720
  163.       TabIndex        =   16
  164.       Top             =   1080
  165.       Width           =   1932
  166.    End
  167.    Begin VB.Label Label1 
  168.       Caption         =   "(For Visual Basic 5.0 using IOPORT OCX)"
  169.       Height          =   252
  170.       Left            =   1200
  171.       TabIndex        =   13
  172.       Top             =   720
  173.       Width           =   3132
  174.    End
  175.    Begin VB.Label lbltitle 
  176.       BackColor       =   &H00C0C0C0&
  177.       Caption         =   "IOPORT Test Program"
  178.       BeginProperty Font 
  179.          Name            =   "Arial"
  180.          Size            =   20.25
  181.          Charset         =   0
  182.          Weight          =   400
  183.          Underline       =   0   'False
  184.          Italic          =   0   'False
  185.          Strikethrough   =   0   'False
  186.       EndProperty
  187.       ForeColor       =   &H00FF0000&
  188.       Height          =   495
  189.       Left            =   720
  190.       TabIndex        =   11
  191.       Top             =   240
  192.       Width           =   4455
  193.    End
  194.    Begin VB.Label lbladdress 
  195.       Caption         =   "I/O Port Address"
  196.       Height          =   252
  197.       Left            =   360
  198.       TabIndex        =   10
  199.       Top             =   3240
  200.       Width           =   1452
  201.    End
  202.    Begin VB.Label Lblbitsize 
  203.       Caption         =   "Size in Bits"
  204.       Height          =   252
  205.       Left            =   360
  206.       TabIndex        =   9
  207.       Top             =   2520
  208.       Width           =   1332
  209.    End
  210.    Begin VB.Label lblread 
  211.       Caption         =   "Value read"
  212.       Height          =   252
  213.       Left            =   360
  214.       TabIndex        =   8
  215.       Top             =   1800
  216.       Width           =   1452
  217.    End
  218.    Begin VB.Label lblwrite 
  219.       Caption         =   "Value to Write"
  220.       Height          =   252
  221.       Left            =   360
  222.       TabIndex        =   7
  223.       Top             =   1080
  224.       Width           =   1452
  225.    End
  226. Attribute VB_Name = "ioporttest"
  227. Attribute VB_GlobalNameSpace = False
  228. Attribute VB_Creatable = False
  229. Attribute VB_PredeclaredId = True
  230. Attribute VB_Exposed = False
  231. 'if the "toggle Bit Size" button is clicked
  232. Private Sub cmdbitsize_Click()
  233. 'then if the IOPORT.bitsize property is currently the value 8
  234. 'change it to 16 and change the labels above the "write" and "read"
  235. 'textboxes to reflect signed and unsigned 16-bit values are being
  236. 'displayed
  237.  If Val(txtbitsize.Text) = 8 Then
  238.     txtbitsize.Text = 16
  239.     Ioport1.bitsize = 16
  240.     lbluswrite.Caption = "Unsigned value Write"
  241.     lblusread.Caption = "Unsigned value Read"
  242.     lblwrite.Caption = "Signed value Write"
  243.     lblread.Caption = "Signed value Read"
  244. 'but if the IOPORT.bitsize property is currently the value 16
  245. 'then change it to 8 and change the labels above the "write" and "read"
  246. 'textboxes to reflect only 8-bit values are being displayed
  247.     txtbitsize.Text = 8
  248.     Ioport1.bitsize = 8
  249.     lbluswrite.Caption = ""
  250.     lblusread.Caption = ""
  251.     lblwrite.Caption = "Value to Write"
  252.     lblread.Caption = "Value Read"
  253.         
  254. End If
  255.     'clear the read and write text boxes...
  256.     txtwrite.Text = ""
  257.     txtuswrite.Text = ""
  258.     txtvalue.Text = ""
  259.     txtusread.Text = ""
  260. End Sub
  261. 'if the "Exit" button is clicked then end the program
  262. Private Sub cmdexit_Click()
  263. End Sub
  264. 'if the "Read from Port" button is clicked
  265. Private Sub cmdread_Click()
  266. 'then if the IOPORT.bitsize value is 8
  267. 'read the value of IOPORT.value to the "Value read" text box and
  268. 'ensure that the "Unsigned value Read" textbox is blank.
  269.   If Val(Ioport1.bitsize) = 8 Then
  270.     txtvalue.Text = Ioport1.Value
  271.     txtusread.Text = ""
  272. 'but if the IOPORT.bitsize value is 16
  273. 'then read the value of IOPORT.value and display it in the "Value read"
  274. 'textbox and read the value of IOPORT.USValue and display it in the
  275. '"Unsigned value Read" textbox
  276.     Else
  277.     txtvalue.Text = Ioport1.Value
  278.     txtusread.Text = Ioport1.USValue
  279.     End If
  280.    End Sub
  281. 'if the "Write to Port" button is clicked
  282. Private Sub cmdwrite_Click()
  283. 'then if the IOPORT.bitzise value is 8 then send the value of the
  284. '"Value to Write" text box to the port and ensure that the "Unsigned
  285. 'value to Write" text box is blank
  286.     If Val(Ioport1.bitsize) = 8 Then
  287.     Ioport1.Value = Val(txtwrite.Text)
  288.     txtuswrite.Text = ""
  289. 'but if the IOPORT.bitsize value is 16 then there are two posibilities:
  290. 'either the user wishes to write a signed 16-bit value, or the user wishes
  291. 'to write an unsigned 16-bit value, the text boxes must be checked to find
  292. 'out which 16-bit format to write
  293.     Else
  294.     'first check to see if there is data in the "Unsigned value to Write"
  295.     'text box, if so this is the format that will be written to the
  296.     'IOPORT.USValue and the "Signed value to Write" text box will be blanked
  297.         If (txtuswrite.Text <> "") Then
  298.         Ioport1.USValue = Val(txtuswrite.Text)
  299.         txtwrite.Text = ""
  300.     'otherwise the data in the "Signed value to Write" will be written to the
  301.     'IOPORT.USValue and the "Unsigned value to Write" will be blanked
  302.         Else
  303.         Ioport1.USValue = Val(txtwrite.Text)
  304.         txtuswrite.Text = ""
  305.         End If
  306.         
  307.     End If
  308. End Sub
  309. 'When the IOTEST application is first loaded...
  310. Private Sub Form_Load()
  311. 'then set these variables to these values....
  312.     address = 888
  313.     bitsize = 8
  314.     Value = 0
  315.  'and display these values in the appropriate text boxes...
  316.     txtaddress = address
  317.     txtbitsize = bitsize
  318.     txtvalue = Value
  319. End Sub
  320. 'When a user clicks on the "I/O Port Address" text box...
  321. Private Sub txtaddress_Click()
  322. 'clear it out to receive a new address value from the user
  323.     txtaddress.Text = ""
  324. End Sub
  325. 'When a user enters a number in the "I/O Port Address" text box
  326. 'and then hits ENTER, (ENTER causes the variable: "KeyAscii" to be equal to 13)
  327. Private Sub txtaddress_KeyPress(KeyAscii As Integer)
  328.     If KeyAscii = 13 Then
  329.         'as long as the value entered is between 0 and 65535..
  330.         If (Val(txtaddress.Text) >= 0) And (Val(txtaddress.Text) <= 65535) Then
  331.         
  332.         'then set the IOPORT.address to this new value
  333.         Ioport1.address = Val(txtaddress.Text)
  334.         
  335.         'otherwise the value entered is out of range, send an error message
  336.         'to the user.
  337.         Else
  338.         MsgBox "I/O Address must be between 0 and 65535!", vbExclamation, "Address Value ERROR"
  339.         
  340.         End If
  341.     End If
  342. End Sub
  343. 'When the user clicks on the "Unsigned value to Write" text box...
  344. Private Sub txtuswrite_Click()
  345.     'clear it out to receive a new unsigned write value from the user
  346.     txtuswrite.Text = ""
  347. End Sub
  348. 'When a user enters a number in the "Unsigned value to Write" text box
  349. 'and then hits ENTER, (ENTER causes the variable: "KeyAscii" to be equal to 13)
  350. Private Sub txtuswrite_KeyPress(KeyAscii As Integer)
  351.     If KeyAscii = 13 Then
  352.     'as long as the value is between 0 and 65535...
  353.         If (Val(txtuswrite.Text) >= 0) And (Val(txtuswrite.Text) <= 65535) Then
  354.         
  355.         'set the IOPORT.USValue to this number
  356.         Ioport1.USValue = Val(txtuswrite.Text)
  357.         
  358.         'otherwise the wrong value was entered, send an error message to the user
  359.         Else
  360.         MsgBox "Unsigned Write value must be between 0 and 65535!", vbExclamation, "Unsigned Write Value ERROR"
  361.         
  362.         'clear out the "Unsigned value to Write" text box..
  363.         txtuswrite.Text = ""
  364.         End If
  365.     End If
  366. End Sub
  367. 'when a user clicks on the "Value to Write" or "Signed value to Write" text box
  368. '(which is the same box, its title depends on 8-bit or 16-bit mode as shown
  369. 'in "Size in Bits" text box)
  370. Private Sub txtwrite_Click()
  371.     'clear it out to receive a new write value from the user
  372.     txtwrite.Text = ""
  373. End Sub
  374. 'When a user enters a number in the "Value to Write" text box
  375. 'and then hits ENTER, (ENTER causes the variable: "KeyAscii" to be equal to 13)
  376. Private Sub txtwrite_KeyPress(KeyAscii As Integer)
  377.     If KeyAscii = 13 Then
  378.     'check to see if IOPORT1.Bitsize is 16
  379.         If Val(Ioport1.bitsize) = 16 Then
  380.         'if bitsize is 16 we must only allow values between -32767 and +32768
  381.          If (Val(txtwrite.Text) >= -32767) And (Val(txtwrite.Text) <= 32768) Then
  382.         
  383.         'set the IOPORT.USValue to this number
  384.         Ioport1.Value = Val(txtwrite.Text)
  385.         
  386.         'otherwise the wrong value was entered, send an error message to the user
  387.         Else
  388.         MsgBox "Signed Write value must be between -32767 and 32678!", vbExclamation, "Signed Write Value ERROR"
  389.         
  390.         'clear out the "Signed value to Write" text box...
  391.         txtwrite.Text = ""
  392.         End If
  393.         
  394.     'if instead, IOPORT1.bitsize is 8..
  395.     Else
  396.     'as long as the value entered is between 0 and 255...
  397.         If (Val(txtwrite.Text) >= 0) And (Val(txtwrite.Text) <= 255) Then
  398.         
  399.         'set the IOPORT.value to this number
  400.         Ioport1.Value = Val(txtwrite.Text)
  401.         
  402.         'otherwise the wrong value was entered, send an error message to the user
  403.         Else
  404.         MsgBox "Write value must be between 0 and 255!", vbExclamation, "Write Value ERROR"
  405.         
  406.         'clear out the "Value to Write" text box..
  407.         txtwrite.Text = ""
  408.         End If
  409.         
  410.     End If
  411. End If
  412. End Sub
  413.